package com.example.myblog.controller;


import com.example.myblog.entity.Message;
import com.example.myblog.exception.BaseException;
import com.example.myblog.result.ResponseBean;
import com.example.myblog.service.MessageService;
import com.example.myblog.vo.MessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 消息管理 前端控制器
 * </p>
 *
 * @author 叶兴
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    MessageService messageService;

    @Autowired
    public void setMessageService(MessageService messageService) {
        this.messageService = messageService;
    }

    /**
     * 发送一条消息
     * @param messageVO
     * @return
     * @throws BaseException
     */
    @PostMapping("/send")
    public ResponseBean sendMessage(MessageVO messageVO) throws BaseException {
        messageService.sendMessage(messageVO);
        return ResponseBean.success();
    }

    /**
     * 获得所有自己曾经发送的消息
     * @return
     * @throws BaseException
     */
    @GetMapping("/messages/send")
    public ResponseBean getSendMessages() throws BaseException {
        List<Message> list = messageService.getSendMessages();
        return ResponseBean.success(list);
    }

    /**
     * 获得所有自己接受到的消息
     * @return
     * @throws BaseException
     */
    @GetMapping("/messages/receive")
    public ResponseBean getReceiveMessages() throws BaseException {
        messageService.getReceiveMessages();
        return ResponseBean.success();
    }
}
